Public Class frmPDVsInactivosNuevos

    Private Shared _instancia As frmPDVsInactivosNuevos

    Public Shared ReadOnly Property Instancia() As frmPDVsInactivosNuevos
        Get
            If _instancia Is Nothing Then
                _instancia = New frmPDVsInactivosNuevos
            End If
            Return _instancia
        End Get
    End Property
#Region "Eventos"
    Private Sub frmPDVsInactivosNuevos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.dtpFecha.Value = Now.AddDays(-7)

        'UsuarioSistema.CodigoCD = "BB01"

        'UsuarioSistema.CodigoCD = "BB01"
        'UsuarioSistema.CodigoTipoRolUsuario = "A"
        'UsuarioSistema.Codigo = 0
        'UsuarioSistema.NombreUsuario = "aborjaar"

        Me.CargarListadoPDVsInactivosNuevos()
    End Sub
    Private Sub frmPDVsInactivosNuevos_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        _instancia = Nothing
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        Me.CargarListadoPDVsInactivosNuevos()
    End Sub
    Private Sub dgrTabla_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgrGrilla.CellDoubleClick

        Me.Seleccionar()

    End Sub
  
    Private Sub dgrGrilla_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgrGrilla.KeyDown

        If e.KeyCode = Keys.Enter Then
            Me.Seleccionar()
        End If

    End Sub
    Private Sub frmPDVsInactivosNuevos_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Keys.Escape = Convert.ToInt32(e.KeyChar) Then

            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Me.Close()

        End If
    End Sub
#End Region
#Region "Procedimientos"
    Private Sub CargarListadoPDVsInactivosNuevos()

        Try
            'CAD.BaseDatos.CrearConexion("BB01")
            Me.dgrGrilla.DataSource = CNG.PDV.ListadoPDVsInactivosNuevos(UsuarioSistema.CodigoCD, dtpFecha.Value)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Cargar Listado PDVs Inactivos Nuevos", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
    End Sub

    Private Sub Seleccionar()
        Dim i As Integer
        Dim miCodigoCD As String
        Dim miCodigo As String

        If Me.dgrGrilla.CurrentCell Is Nothing = False Then

            i = Me.dgrGrilla.CurrentRow.Index

            miCodigoCD = Me.dgrGrilla("CodigoCD", i).Value
            miCodigo = Me.dgrGrilla("Codigo", i).Value

            Dim miFormulario As New frmPDV(miCodigoCD, miCodigo)
            miFormulario.ShowDialog()
            Me.CargarListadoPDVsInactivosNuevos()
        End If
    End Sub
#End Region



End Class
